//
//  GKZYUserForgetPasswordViewController.m
//  GKZYAid
//
//  Created by lanou3g on 16/3/14.
//  Copyright © 2016年 GKZYAid. All rights reserved.
//

#import "GKZYUserForgetPasswordViewController.h"

@interface GKZYUserForgetPasswordViewController ()

@end

@implementation GKZYUserForgetPasswordViewController

- (void)loadView
{
    self.forgetPasswordView = [[GKZYUserForgetPasswordView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.view = self.forgetPasswordView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"找回密码";
    [self setButtonSureAction];
}

- (void)setButtonSureAction
{
    [self.forgetPasswordView.buttonSure addTarget:self action:@selector(buttonSureAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)buttonSureAction:(UIButton *)sender
{
    [self getUserMessage];
    [AVUser requestPasswordResetForEmailInBackground:self.strUserMail block:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            [self addSendSucceedAlertController];
        }else{
            NSLog(@"%@",error);
        }
    }];
}

- (void)getUserMessage
{
    [self.forgetPasswordView.userName.LTTextField resignFirstResponder];
    [self.forgetPasswordView.userMail.LTTextField resignFirstResponder];
    self.strUserName = self.forgetPasswordView.userName.LTTextField.text;
    self.strUserMail = self.forgetPasswordView.userMail.LTTextField.text;
}

- (void)addSendSucceedAlertController
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"邮件已发送,请注意查收!" message:@"" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        GKZYUserLoginViewController *loginView = [[GKZYUserLoginViewController alloc] init];
        [self.navigationController pushViewController:loginView animated:YES];
    }];
    [alertController addAction:alertAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
